package com.zhuannimei.adapter;

import java.util.List;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ProgressBar;
import android.widget.TextView;

import com.zhuannimei.R;
import com.zhuannimei.domain.OneShopProduct;
import com.zhuannimei.utility.JackViewHolder;
import com.zhuannimei.utility.UrlBank;
import com.zhuannimei.utility.WuLog;

/**
 * only one yuan,You may get a Iphone
 * 
 * @author Jack 2014-3-4
 * 
 * 
 */
public class OneShopAdapter extends BaseObjectListAdapter {
	
	private static final String TAG = "OneShopAdapter";

	public OneShopAdapter(Context context, List<? extends Object> datas) {
		super(context, datas);
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		if (convertView == null) {
			convertView = mInflater.inflate(R.layout.znm_shop_one_item, null);
		}

		OneShopProduct osp = (OneShopProduct) mDatas.get(position);
		// 活动图片
		ImageView one_shop_iv_photo = JackViewHolder.get(convertView,
				R.id.one_shop_iv_photo);
		String url = UrlBank.getServerIp()+osp.getPicture();
		WuLog.i(TAG, "url=="+url);
		imageLoader.displayImage(url, one_shop_iv_photo, options);
		// 活动主题
		TextView one_shop_tv_title = JackViewHolder.get(convertView,
				R.id.one_shop_tv_title);
		one_shop_tv_title.setText("第" + osp.getPhase() + "期 " + osp.getTitle());

		// 活动所需积分
		TextView one_shop_tv_price = JackViewHolder.get(convertView,
				R.id.one_shop_tv_price);
		one_shop_tv_price.setText(osp.getBuyed() + "妹币");

		// 市场价格
		TextView one_shop_tv_jiage = JackViewHolder.get(convertView,
				R.id.one_shop_tv_jiage);
		one_shop_tv_jiage.setText("原价:" + osp.getPrice() + "元");

		// 参与人数
		TextView canyu_tv_people = JackViewHolder.get(convertView,
				R.id.canyu_tv_people);
		canyu_tv_people.setText("" + osp.getJoins());

		// 总人数
		TextView total_tv_people = JackViewHolder.get(convertView,
				R.id.total_tv_people);
		total_tv_people.setText("" + osp.getTotal());
		// 剩余人数
		TextView shengyu_tv_people = JackViewHolder.get(convertView,
				R.id.shengyu_tv_people);
		shengyu_tv_people.setText("" + osp.getLast());
		// 人数进度条
		ProgressBar one_shop_people_num = JackViewHolder.get(convertView,
				R.id.one_shop_people_num);
		one_shop_people_num.setMax(Integer.parseInt(osp.getTotal()));
		one_shop_people_num.setProgress(Integer.parseInt(
				osp.getJoins()));
		
		ImageView status = JackViewHolder.get(convertView, R.id.product_status_iv);
		if("0".equals(osp.getLast())){
			status.setBackgroundResource(R.drawable.label_announced);
		}else{
			status.setBackgroundResource(R.drawable.label_in_progress);
		}
		return convertView;
	}

}
